
$(function() {	
	$("select[id^='type_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	});
});

var Qr = {
	content_x: function(form) {
		var type = form.type.value;
				
		var body = { };	
		if (type == '4') {			
			body.to = form.x_to.value;
			body.content = form.x_content.value;
		} else if (type == '5') {			
			body.to = form.x_to.value;
			body.title = form.x_title.value;
			body.content = form.x_content.value;
		} else if (type == '6') {			
			body.name = form.x_name.value;
			body.bday = form.x_bday.value;
			body.job = form.x_job.value;
			body.org = form.x_org.value;
			body.url = form.x_url.value;
			body.adr = form.x_adr.value;
			body.tel = form.x_tel.value;
			body.fax = form.x_fax.value;
			body.cell = form.x_cell.value;
			body.email = form.x_email.value;
			body.geo = form.x_geo.value;
			body.content = form.x_content.value;	
			
		} else if (type == '7') {			
			body.ssid = form.x_ssid.value;
			body.password = form.x_password.value;
			body.safe = form.x_safe.value;
		} 
		
		return $.toJSON(body);
	},
	
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];

				var body = { };
				body.emp = form.emp.value;
				body.type = form.type.value;
				
				body.level = form.level.value;
				body.size = form.size.value;
				
				body.name = form.name.value;								
				body.content = form.content.value;
								
				body.content_x = Qr.content_x(form);

				$(this).dialog("close");

				$.post('info.php?do=Qr.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	},	

	popup: function (e, p2, id, type, status) {
		$.cookie('id_', id);
		
		p2 = query(p2);
		$.cookie('p2', p2);
		
		var c1 = 'info.php?do=Qr.edit&id=' + id;	
		var c2 = 'info.php?do=Qr.copy&id=' + id;
		var c3 = 'info.php?do=Qr.view&id=' + id;

		var a1 = ['编辑信息', 'url', 'Qr.dialog_edit_', '720x450'];
		var a2 = ['复制信息', 'url', 'Qr.dialog_copy_', '720x450'];
		
		var a3 = ['查看信息', 'url', 'Common.dialog_view_', '600x400'];
		
		var s = c1 + ", " + c2 + ", " + c3;

		this.popup_(e, [a1, a2, a3], s);
	},
	
	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var ss = 'info.php?do=Qr.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Qr.dialog_ss', '400x200'];
		
		s += ", " + ss;
		a.push(bb);
		
		return popup(e, a, s);
	},

	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('info.php?do=Qr.audit&item=147', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'info.php?do=Qr.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				
				body.emp = form.emp.value;
				body.type = form.type.value;
				
				body.level = form.level.value;
				body.size = form.size.value;
				
				body.name = form.name.value;								
				body.content = form.content.value;
				
				body.content_x = Qr.content_x(form);

				$(this).dialog("close");

				var url = 'info.php?do=Qr.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_edit")[0];
				
				var body = {};
				
				body.emp = form.emp.value;
				body.type = form.type.value;
				
				body.level = form.level.value;
				body.size = form.size.value;
				
				body.name = form.name.value;								
				body.content = form.content.value;
				
				body.content_x = Qr.content_x(form);

				$(this).dialog("close");

				var url = 'info.php?do=Qr.addPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	}
	
};
